package com.itcp.itelpicture.controller;


import com.itcp.itelpicture.common.BaseResponse;
import com.itcp.itelpicture.common.Result;
import com.itcp.itelpicture.domain.dto.remark.LikeRecordFormDTO;
import com.itcp.itelpicture.domain.po.User;
import com.itcp.itelpicture.domain.vo.UserVO;
import com.itcp.itelpicture.service.ILikeRecordService;
import com.itcp.itelpicture.service.IUserService;
import com.itcp.itelpicture.utils.UserHolder;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Set;

/**
 * <p>
 * 点赞记录表 前端控制器
 * </p>
 *
 * @author wgzz
 * @since 2025-04-20
 */
@RestController
@RequestMapping("/likes")
@RequiredArgsConstructor
public class LikeRecordController {

    private final ILikeRecordService recordService;

    private final IUserService userService;

    @ApiOperation("点赞或取消点赞")
    @PostMapping
    public void addLikeRecord(@RequestBody LikeRecordFormDTO likeRecordFormDTO, HttpServletRequest request){
        User user = userService.getLoginUser(request);
        recordService.addLikeRecord(likeRecordFormDTO, user);
    }

    @GetMapping("/isLiked")
    @ApiOperation("查询指定业务id的点赞状态")
    public BaseResponse<Boolean> isBizLiked(@RequestParam("objectId") Long objectId){
        UserVO user = UserHolder.getUser();
        if (user == null) return Result.success(false);
        return Result.success(recordService.isBizLiked(objectId, user));
    }

}
